// Include Files
#include "Main\GLExt.h"

// Namespace
namespace IE
{
	// TODO: where
	PFN_glVertexAttribPointer glVertexAttribPointer;
	PFN_glEnableVertexAttribArray glEnableVertexAttribArray;

	// GL_vertex_buffer_object
	PFN_glBindBuffer glBindBuffer;
	PFN_glDeleteBuffers glDeleteBuffers;
	PFN_glGenBuffers glGenBuffers;
	PFN_glIsBuffer glIsBuffer;
	PFN_glBufferData glBufferData;
	PFN_glBufferSubData glBufferSubData;
	PFN_glGetBufferSubData glGetBufferSubData;
	PFN_glMapBuffer glMapBuffer;
	PFN_glUnmapBuffer glUnmapBuffer;
	PFN_glGetBufferParameteriv glGetBufferParameteriv;
	PFN_glGetBufferPointerv glGetBufferPointerv;

	// WGL_pixel_format
	PFN_wglGetPixelFormatAttribiv wglGetPixelFormatAttribiv;
	PFN_wglGetPixelFormatAttribfv wglGetPixelFormatAttribfv;
	PFN_wglChoosePixelFormat      wglChoosePixelFormat;

	// WGL_create_context_profile
	PFN_wglCreateContextAttribs   wglCreateContextAttribs;

	// GL_vertex_array_object
	PFN_glBindVertexArray         glBindVertexArray;
	PFN_glDeleteVertexArrays      glDeleteVertexArrays;
	PFN_glGenVertexArrays         glGenVertexArrays;
	PFN_glIsVertexArray           glIsVertexArray;
}

bool IE::GLExtInit()
{
	// TODO: where
	glVertexAttribPointer     = (PFN_glVertexAttribPointer)
		wglGetProcAddress("glVertexAttribPointer");
	glEnableVertexAttribArray = (PFN_glEnableVertexAttribArray)
		wglGetProcAddress("glEnableVertexAttribArray");

	assert( glVertexAttribPointer && glEnableVertexAttribArray );

	// GL_vertex_buffer_object
	glBindBuffer           = (PFN_glBindBuffer)
		wglGetProcAddress("glBindBuffer");
	glDeleteBuffers        = (PFN_glDeleteBuffers)
		wglGetProcAddress("glDeleteBuffers");
	glGenBuffers           = (PFN_glGenBuffers)
		wglGetProcAddress("glGenBuffers");
	glIsBuffer             = (PFN_glIsBuffer)
		wglGetProcAddress("glIsBuffer");
	glBufferData           = (PFN_glBufferData)
		wglGetProcAddress("glBufferData");
	glBufferSubData        = (PFN_glBufferSubData)
		wglGetProcAddress("glBufferSubData");
	glGetBufferSubData     = (PFN_glGetBufferSubData)
		wglGetProcAddress("glGetBufferSubData");
	glMapBuffer            = (PFN_glMapBuffer)
		wglGetProcAddress("glMapBuffer");
	glUnmapBuffer          = (PFN_glUnmapBuffer)
		wglGetProcAddress("glUnmapBuffer");
	glGetBufferParameteriv = (PFN_glGetBufferParameteriv)
		wglGetProcAddress("glGetBufferParameteriv");
	glGetBufferPointerv    = (PFN_glGetBufferPointerv)
		wglGetProcAddress("glGetBufferPointerv");

	assert( 
		glBindBuffer && glDeleteBuffers && glGenBuffers && glIsBuffer && 
		glBufferData && glBufferSubData && glGetBufferSubData && glMapBuffer && 
		glUnmapBuffer && glGetBufferParameteriv && glGetBufferPointerv 
		);

	// WGL_pixel_format
	wglGetPixelFormatAttribiv = (PFN_wglGetPixelFormatAttribiv)
		wglGetProcAddress("wglGetPixelFormatAttribivARB");
	wglGetPixelFormatAttribfv = (PFN_wglGetPixelFormatAttribfv)
		wglGetProcAddress("wglGetPixelFormatAttribfvARB");
	wglChoosePixelFormat      = (PFN_wglChoosePixelFormat)
		wglGetProcAddress("wglChoosePixelFormatARB");

	assert(
		wglGetPixelFormatAttribiv && wglGetPixelFormatAttribfv && 
		wglChoosePixelFormat
		);

	// WGL_create_context_profile
	wglCreateContextAttribs = (PFN_wglCreateContextAttribs)
		wglGetProcAddress("wglCreateContextAttribsARB");

	assert(wglCreateContextAttribs);

	// GL_vertex_array_object
	glBindVertexArray    = (PFN_glBindVertexArray)
		wglGetProcAddress("glBindVertexArray");
	glDeleteVertexArrays = (PFN_glDeleteVertexArrays)
		wglGetProcAddress("glDeleteVertexArrays");
	glGenVertexArrays    = (PFN_glGenVertexArrays)
		wglGetProcAddress("glGenVertexArrays");
	glIsVertexArray      = (PFN_glIsVertexArray)
		wglGetProcAddress("glIsVertexArray");

	assert( 
		glBindVertexArray && glDeleteVertexArrays && 
		glGenVertexArrays && glIsVertexArray 
		);

	return GL_TRUE;
}
